package com.guoxue.dao.impl;

import java.util.List;


import org.springframework.stereotype.Repository;
import com.guoxue.dao.IUserDao;
import com.guoxue.domain.UserVo;

@Repository("userDaoImpl")
public class UserDaoImpl extends BaseDaoImpl<UserVo> implements IUserDao{
	
	
	public UserVo getUser(String account) {
		return get(" from UserVo u where u.identityId = ? or u.wechatAccount =? or u.sinaAccount =? or u.qqAccount =? or u.userTel=?", new Object[] {account, account, account, account, account});
	}

	
	public UserVo getUserById(String identityId) {
		return get("from UserVo u where u.identityId = ?", new Object[] {identityId});
	}
	

	public List<UserVo> getUserList() {
		return find("from UserVo u");
	}
	
	public void saveUser(UserVo user) {
		saveOrUpdate(user);
	}

	public UserVo getUserByTel(String account) {
		return get("from UserVo u where u.userTel = ?", new Object[] {account});
	}

	public UserVo getUserByNickname(String nickName) {
		return get("from UserVo u where u.nickName = ?", new Object[] {nickName});
	}
	
	public int updateUserNickName(String nickName, String account){
		return executeHql("update UserVo u set u.nickName = ? where u.userTel = ? or u.wechatAccount =? "
				+ "or u.sinaAccount = ? or u.qqAccount = ? or u.identityId = ?", new Object[] {nickName,account,account
						,account,account,account});
	}

	public void updateAccountStatus(int id, int status) {
		executeHql("UPDATE UserVo u set u.status=? WHERE u.id=?", new Object[] {status,id});
	}
	@Override
	public UserVo getUserByKey(int id) {
		return get("from UserVo u where u.id = ?", new Object[] {id});
	}
	
	
	
}
